home *** CD-ROM | disk | FTP | other *** search
- // Copyright (c)1995 Ray Dream, Inc. All Rights Reserved.
- /* $Id: Checker.cpp 1.3 1997/04/11 01:21:39 damien Exp $ */
- //
- // Implementation of the Checker Shader
- //
-
- #include "math.h"
-
- #ifndef __CHECKER__
- #include "Checker.h"
- #endif
-
- #ifndef __SHDRDLL__
- #include "Shdrdll.h"
- #endif
-
- #undef INTERFACE
- #define INTERFACE CheckerShader
-
- // Checker Constructor :
- CheckerShader::CheckerShader() {
- CheckerPublicData.nbSquareU = CheckerPublicData.nbSquareV = 8; // Default Value of the checker
- };
-
- // Checker Destructor :
- CheckerShader::~CheckerShader() {
- global_count_Obj--; // used by the DLL to know if it can be unloaded
- // the variable is global and defines in "Shadrdll.cpp"
- }
-
- // How to Clone the Checker
- I3DExtension* CheckerShader::Clone(THIS) {
- CheckerShader* theClone = new CheckerShader; // Create New Checker
- CopyData(theClone); // Copy Data in the new Checker
- theClone->AddRef();
- return theClone;
- }
-
- short CheckerShader::GetResID(THIS) {
- return 128; // Ressource ID for the Shell
- }
-
- // Give a pointer to the public data that the shell can modify
- void* CheckerShader::GetExtensionDataBuffer(THIS) {
- return ((void*) &(CheckerPublicData));
- }
-
- // Compare two Shader
- BOOLEAN CheckerShader::IsEqualTo(THIS_ I3DExShader* aShader) {
- return ((CheckerPublicData.nbSquareU==((CheckerShader*)aShader)->CheckerPublicData.nbSquareU)
- && (CheckerPublicData.nbSquareV==((CheckerShader*)aShader)->CheckerPublicData.nbSquareV));
- }
-
- BOOLEAN CheckerShader::DependsOnAppliedExtent(THIS) {
- return TRUE; // The Checker uses the UV Space coordinate
- }
-
- HRESULT CheckerShader::DoShade(THIS_ ShadingInOut* /*theShadingIO*/, ShadingElem* /*theShadingElem*/) {
- return ResultFromScode(E_NOTIMPL);
- }
-
- #define MyEven(xx) (!(((long)(xx)) & 0x00000001)) // to know if xx is Even or Odd
-
- ULONG CheckerShader::GetPreferredOutput(THIS) {
- return kUsesGetValue; // Tell the Shell that this Shader returns a Value
- }
-
- HRESULT CheckerShader::GetValue(THIS_ NUM3D* result, ShadingIn* theShadingIn, ShadingElem* theShadingElem) {
- if (!fPreprocessed) { // Coefficient factors is not already calculated
- fMul[0]= ((NUM3D)CheckerPublicData.nbSquareU) / (theShadingElem->fShaderBox.fRight - theShadingElem->fShaderBox.fLeft);
- fMul[1]= ((NUM3D)CheckerPublicData.nbSquareV) / (theShadingElem->fShaderBox.fTop - theShadingElem->fShaderBox.fBottom);
- fPreprocessed = TRUE;
- }
- NUM3D nu = (theShadingIn->fUV[0]-theShadingElem->fShaderBox.fLeft) * fMul[0];
- NUM3D nv = (theShadingIn->fUV[1]-theShadingElem->fShaderBox.fBottom) * fMul[1];
- if (MyEven(floor(nu) + floor(nv))) {
- *result = 0.0;
- }
- else {
- *result = 1.0;
- }
- return NOERROR;
- }
-
- // You must create these functions to create an non-abstract Object
- HRESULT CheckerShader::GetColor(THIS_ COLOR3D* result, ShadingIn* theShadingIn, ShadingElem* theShadingElem) {
- return ResultFromScode(E_NOTIMPL);
- }
-
- HRESULT CheckerShader::GetVector(THIS_ VECTOR3D* result, ShadingIn* theShadingIn, ShadingElem* theShadingElem) {
- return ResultFromScode(E_NOTIMPL);
- }
-
- // Set the flags of the Shader
- HRESULT CheckerShader::GetShadingFlags(THIS_ ShadingFlags* theFlags) {
- theFlags->fNeedsUV = TRUE;
- theFlags->fCallOnce = FALSE;
- return NOERROR;
- }
-
- // Function to Clone the Object
- void CheckerShader::CopyData(COMShader* dest) {
- COMShader::CopyData(dest); // Copy Data of the inherited object (Shader)
- ((CheckerShader*)dest)->CheckerPublicData=CheckerPublicData; // Copy Public Data
- ((CheckerShader*)dest)->fMul[0]=fMul[0];
- ((CheckerShader*)dest)->fMul[1]=fMul[1]; // Copy Preprocessed Data
- }
-
- // If you don't use a ressource that can give the type of the different
- // data in the CheckerShaderPublicData you have to give a pointer on this
- // Properties Map
- ExtensionDataMap* CheckerShader::GetExtensionDataMap(THIS) {
- return NULL;
- }
-
-
-